package de.koller.eccentricity.render;

import de.koller.eccentricity.ENode;
import de.koller.eccentricity.render.obj.GridFloor;
import de.koller.eccentricity.render.obj.IERenderObj;
import de.koller.eccentricity.render.texture.ETextures;
import de.koller.oceanFramework.tree.Child;
import org.lwjgl.opengl.GL11;

public class ERender extends ENode {
	
	@Child public final ECamera camera = new ECamera();
	@Child public final ETextures texture = new ETextures();
	
	private final IERenderObj floor = new GridFloor();
	private int vaoid;
	
	@Override
	protected void init() {
		super.init();
		
		//vaoid = GL30.glGenVertexArrays();
		
//		GL11.glEnable( GL11.GL_CULL_FACE );
//		GL11.glCullFace( GL11.GL_BACK );

		GL11.glEnable( GL11.GL_DEPTH_TEST );
		GL11.glDepthFunc( GL11.GL_LEQUAL );
		
		GL11.glAlphaFunc( GL11.GL_GREATER, 0.01f );
		GL11.glEnable( GL11.GL_ALPHA_TEST );
	}
	
	public void renderGame( int elapsedTime ) {		
		camera.setupProjection();
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
		
		GL11.glDisable( GL11.GL_TEXTURE_2D );
		GL11.glColor3f( 1, 1, 1 );
		GL11.glBegin( GL11.GL_QUADS );
			GL11.glVertex3f( -.5f, -.5f, 0 );
			GL11.glVertex3f( -.5f,  .5f, 0 );
			GL11.glVertex3f(  .5f,  .5f, 0 );
			GL11.glVertex3f(  .5f, -.5f, 0 );
		GL11.glEnd();
		
		floor.renderObj( this );
	}
	
}
